<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

	</head>
	<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
	<link rel="stylesheet" type="text/css" href="../css/goods/share_group.css" />
	<script type="text/javascript">
		(function() {
			var clientWidth = document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth;
			clientWidth = clientWidth || localStorage.getItem("clientWidth")
			if(clientWidth > 750)
				clientWidth = 750;
			document.documentElement.style.fontSize = clientWidth * 1 / 16 + "px";
		})();
	</script>
	<style type="text/css">
		.join_user_img {
			margin-right: 0.2rem;
		}
	</style>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">分享拼团</h1>
		</header>
		<div class='mui-content content'>
			<div class="hr_20"></div>
			<div class='img' @click="open_goods">
				<img :src='order_info.pic'>
				<div class='txt'>
					<span>{{order_info.name}}</span>
				</div>
			</div>
			<div class='con'>
				<div class='p'>还差
					<span>{{num}}</span>人</div>
				<div class='portrait'>
					<div class="join_user_img" v-for="(i,k) in order_info.head">
						<img :src='i.head' v-show="i">
					</div>

				</div>
				<div class='time'>
					<span>{{time}}后结束</span>
				</div>
				<button class='buttom' @click="open_goods">参加活动</button>
				<div class='rule'>*规则说明</div>
			</div>
		</div>

		<script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>

		<script src="../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/tools/share_config.js" type="text/javascript" charset="utf-8"></script>
		<!--<script src="../js/tools/share.js" type="text/javascript" charset="utf-8"></script>-->
		<script src="../js/tools/util.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var share = {
				get_share: function(callback) {
					util.log("get_share")
					plus.share.getServices(

						function(e) {
							util.log(JSON.stringify(e))
							var share_list = {};
							util.log(JSON.stringify(e))
							//			console.log(JSON.stringify(e));
							for(var i = 0; i < e.length; i++) {

								if(e[i].id == "weixin") {
									share_list.weixin = e[i]
								}

							};
		
							callback(share_list);
						},

						function(e) {
							console.log(e)
						}
					);
				}

			}
			var app = new Vue({
				el: '.content',
				data: {
					order_info: '',
					time: '',
					plus_ready: false,
					orderid:''
				},
				methods: {
					open_goods:function(){
						util.log(window.location.href);
			 			var sid = util.GetQueryString("sid")
						mui.openWindow("goods_detail.html?goodsid="+this.order_info.goods_id+"&sid="+sid)
					},
					//分享方法
					share_fun: function(n) {
						/*
						 * n 为分享类型
						 * 		1	-->	分享好友
						 * 		2	-->	分享朋友圈
						 * 		3	-->	分享QQ
						 * 		4	-->	复制链接
						 * 
						 * 
						 * */
						
						util.log("share_fun")
						console.log(this.order_info)
			 
						var that = this;
						if(!this.plus_ready) {
							mui.toast("plus未准备就绪");
							return;
						}
						var n = 1;
						
						
						
						switch(n) {
							case 1:
								util.log("share_fun  switch  1 ")
								util.log(this.plus_ready)
								share.get_share(function(share_list) {
									console.log("-----")
									util.log(JSON.stringify(share_list))
									util.log(JSON.stringify(share_list))

									var msg = share_config;
									var orderid = util.GetQueryString("orderid");
									console.log("orderid-->" + orderid)
									msg.href = msg.href + "?type=share_group&id="+orderid
									
									msg.title = that.order_info.name; //分享标题
									msg.content = "还差"+that.num +"人拼团成功!"   ;    //分享描述
									msg.thumbs = that.order_info.pic
									util.log("分享信息-->> " + JSON.stringify(msg))

									msg.extra.scene = 'WXSceneSession'
									shareAction(share_list.weixin, msg)
								})

								break;
							case 2:
								share.get_share(function(share_list) {
									var msg = share_config;
									var orderid = util.GetQueryString("orderid");
									console.log("orderid-->" + orderid)
									msg.href = msg.href + "?type=share_group&id="+orderid
									msg.title = that.order_info.name; //分享标题
									msg.content = "还差"+that.num +"人拼团成功!"   ;    //分享描述
									msg.thumbs = that.order_info.pic
									util.log("分享信息-->> " + JSON.stringify(msg))

									msg.extra.scene = 'WXSceneTimeline'
									shareAction(share_list.weixin, msg)
								})
								break;
							case 3:
								alert('分享QQ 开发中')
								break;
							case 4:
								alert('复制链接 开发中')
								break;
							default:
								break;
						}
					}

				},
				computed: {
					num: function() {
						return parseInt(this.order_info.count) - parseInt(this.order_info.headlength)
					}
				},
				created: function() {
					mui.plusReady(function() {
						console.log("plusReady")
						app.plus_ready = true;
					})
					console.log(1111)
					
					var orderid = util.GetQueryString("orderid");
					console.log("orderid-->" + orderid)
					this.orderid = orderid
					var that = this
					$.ajax({
						type: 'get',
						url: 'https://zhapp.4hl.cn/app/spell/SpellGroupGhare',
						data: {
							orderid: orderid,

						},
						success: function(res) {
							console.log(res)
							res = JSON.parse(res);
							that.order_info = res.data;
							console.log(res.data)
							uctime(res.data.spellouttime)
						},
						error: function(err) {
							alert("服务器错误")
						}

					})
				}
			})

			var uctime = function(time) {

				var t;
				if(time > -1) {
					var day = Math.floor(time / 3600 / 24); //天
					//console.log(day,'------------')
					var hour = Math.floor(time / 3600) % 24; //时
					//console.log(hour,'hourhour')
					var min = Math.floor(time / 60) % 60; //分
					var sec = time % 60; //秒
					t = day + '天'
					if(hour < 10) {
						t += '0' + hour + "时";
					} else {
						t += hour + "时";
					}
					if(min < 10) {
						t += "0";
					}
					t += min + "分";
					console.log(t, 'ttttttttt')
					if(sec < 10) {
						t += "0";
					}
					t += sec //.toFixed(2);
				}

				var set;
				set = setInterval(function() {
					var t;
					time = time - 1
					if(time > -1) {
						var day = Math.floor(time / 3600 / 24); //天
						//console.log(day,'------------')
						var hour = Math.floor(time / 3600) % 24; //时
						//console.log(hour,'hourhour')
						var min = Math.floor(time / 60) % 60; //分
						var sec = time % 60; //秒
						t = day + '天'
						if(hour < 10) {
							t += '0' + hour + "时";
						} else {
							t += hour + "时";
						}
						if(min < 10) {
							t += "0";
						}
						t += min + "分";
						console.log(t, 'ttttttttt')
						if(sec < 10) {
							t += "0";
						}
						t += sec //.toFixed(2);
					}
					console.log(t);
					app.time = t

				}, 1000)

				//console.log(t)
			}
			
			//分享操作
function shareAction(s,msg) {
	if ( !s ) {
		return;
	}
	if ( s.authenticated ) {
		shareMessage( s,msg );
	} else {
		s.authorize( shareMessage, function(e){
			alert( "未进行认证" );
		});
	}
}
//发送分享消息
function shareMessage(s,msg){
	s.send( msg, function(){
		mui.toast( "分享成功！" );
	}, function(e){
		mui.toast( "分享失败！" );
//		alert( "分享失败："+e.message );
	} );
}
		</script>
	</body>

</html>